/**
	Copyright (c) 2009 ATTi 
	All rights reserved.
*/

trigger caseAssignedDate on Case (before update) {
	if(trigger.isBefore){
		if(caseAssignedDateClass.getIsFirstBefore()){
			Id curOwnerId, newOwnerId;
			List<Case> lCase = new List<Case>();
			
			for(Case cs : Trigger.new){
				curOwnerId = Trigger.oldMap.get(cs.Id).OwnerId;
				newOwnerId = cs.OwnerId;
				if(!cs.IsClosed && curOwnerId != newOwnerId && !caseAssignedDateClass.IOGRecordTypeIDs.contains(cs.RecordTypeId)){
					lCase.add(cs);
				}
			}
			if(!lCase.isEmpty()){
				Map<Id, User> mUser = caseAssignedDateClass.getMUser();
				for(Case c : lCase){
					if(mUser.containsKey(c.OwnerId)){
						c.Assigned_Date__c = datetime.now();
					}
				}
			}
		}
	}
}